
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>框架之 hibernate之各种查询 - oldmonk - 博客园</title>
<link type="text/css" rel="stylesheet" href="/bundles/blog-common.css?v=H3IOkgdPffpmgIkls4TofKh6PlSWVifjfgEhZr2VHqo1"/>
<link id="MainCss" type="text/css" rel="stylesheet" href="/skins/coffee/bundle-coffee.css?v=NnZbvdgFaQNhu3t8P4Wsaz98sDQkgRt7Qxq2rzF0ZRU1"/>
<link type="text/css" rel="stylesheet" href="/blog/customcss/234959.css?v=n5EazlmuF0SPMKXwU5udei4wBPM%3d"/>
<link id="mobile-style" media="only screen and (max-width: 767px)" type="text/css" rel="stylesheet" href="/skins/coffee/bundle-coffee-mobile.css?v=EhLLUe5NHsx18JODVZscd5ef3A8WbJHKTlTvuKQjsl01"/>
<link title="RSS" type="application/rss+xml" rel="alternate" href="http://www.cnblogs.com/xujingyang/rss"/>
<link title="RSD" type="application/rsd+xml" rel="EditURI" href="http://www.cnblogs.com/xujingyang/rsd.xml"/>
<link type="application/wlwmanifest+xml" rel="wlwmanifest" href="http://www.cnblogs.com/xujingyang/wlwmanifest.xml"/>
<script src="//common.cnblogs.com/script/jquery.js" type="text/javascript"></script>  
<script type="text/javascript">var currentBlogApp = 'xujingyang', cb_enable_mathjax=true;var isLogined=false;</script>
<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
        tex2jax: { inlineMath: [['$','$'], ['\\(','\\)']], processClass: 'blogpost-body', processEscapes: true },
        TeX: { 
            equationNumbers: { autoNumber: ['AMS'], useLabelIds: true }, extensions: ['extpfeil.js'] },
            'HTML-CSS': { linebreaks: { automatic: true } },
            SVG: { linebreaks: { automatic: true } }
        });
    </script><script src="//mathjax.cnblogs.com/2_7_2/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script src="/bundles/blog-common.js?v=Gjc-c4WOecxW2V4mwH9-EN2lPzwMWd4wyAzo535GvA01" type="text/javascript"></script>
<style type="text/css">
[id^="ad_"] {display:none!important;display:none}</style>
</head>
<body>
<a name="top"></a>

<!--done-->
<div id="home">
<div id="header">
	<div id="blogTitle">
	<a id="lnkBlogLogo" href="http://www.cnblogs.com/xujingyang/"><img id="blogLogo" src="/Skins/custom/images/logo.gif" alt="返回主页" /></a>			
		
<!--done-->
<h1><a id="Header1_HeaderTitle" class="headermaintitle" href="http://www.cnblogs.com/xujingyang/">oldmonk</a></h1>
<h2>没什么学不会的,就看你努力不努力...</h2>



		
	</div><!--end: blogTitle 博客的标题和副标题 -->
</div><!--end: header 头部 -->

<div id="main">
	<div id="mainContent">
	<div class="forFlow">
		<div id="navigator">
			
<ul id="navList">
	<li><a id="blog_nav_sitehome" class="menu" href="http://www.cnblogs.com/">博客园</a></li>
	<li><a id="blog_nav_myhome" class="menu" href="http://www.cnblogs.com/xujingyang/">首页</a></li>
	<li><a id="blog_nav_newpost" class="menu" rel="nofollow" href="https://i.cnblogs.com/EditPosts.aspx?opt=1">新随笔</a></li>
	<li><a id="blog_nav_contact" accesskey="9" class="menu" rel="nofollow" href="https://msg.cnblogs.com/send/oldmonk">联系</a></li>
	<li><a id="blog_nav_admin" class="menu" rel="nofollow" href="https://i.cnblogs.com/">管理</a></li>
	<li><a id="blog_nav_rss" class="menu" href="http://www.cnblogs.com/xujingyang/rss">订阅</a>
	<a id="blog_nav_rss_image" class="aHeaderXML" href="http://www.cnblogs.com/xujingyang/rss"><img src="//www.cnblogs.com/images/xml.gif" alt="订阅" /></a></li>
</ul>


			<div class="blogStats">
				
				<div id="blog_stats">
<!--done-->
随笔- 126&nbsp;
文章- 0&nbsp;
评论- 1&nbsp;
</div>
				
			</div><!--end: blogStats -->
		</div><!--end: navigator 博客导航栏 -->
		
<div id="post_detail">
<!--done-->
<div id="topics">
	<div class = "post">
		<h1 class = "postTitle">
			<a id="cb_post_title_url" class="postTitle2" href="http://www.cnblogs.com/xujingyang/p/6734203.html">框架之 hibernate之各种查询</a>
		</h1>
		<div class="clear"></div>
		<div class="postBody">
			<div id="cnblogs_post_body" class="blogpost-body"><pre><code>1. Hibernate的查询方式
2. Hibernate的查询策略
</code></pre>
<hr />
<h3>案例：使用Hibernate完成查询所有联系人功能</h3>
<hr />
<p><strong>需求分析</strong></p>
<pre><code>1. 完成所有的联系人的查询
</code></pre>
<hr />
<p><strong>技术分析之Hibernate框架的查询方式</strong></p>
<pre><code>1. 唯一标识OID的检索方式
    * session.get(对象.class,OID)
2. 对象的导航的方式

3. HQL的检索方式
    * Hibernate Query Language  -- Hibernate的查询语言

4. QBC的检索方式
    * Query By Criteria -- 条件查询

5. SQL检索方式（了解）
    * 本地的SQL检索
</code></pre>
<hr />
<p><strong>技术分析之HQL的查询方式概述</strong></p>
<pre><code>1. HQL的介绍
    * HQL(Hibernate Query Language) 是面向对象的查询语言, 它和 SQL 查询语言有些相似
    * 在 Hibernate 提供的各种检索方式中, HQL 是使用最广的一种检索方式

2. HQL与SQL的关系
    * HQL 查询语句是面向对象的,Hibernate负责解析HQL查询语句, 然后根据对象-关系映射文件中的映射信息, 把 HQL 查询语句翻译成相应的 SQL 语句. 
    * HQL 查询语句中的主体是域模型中的类及类的属性
    * SQL 查询语句是与关系数据库绑定在一起的. SQL查询语句中的主体是数据库表及表的字段
</code></pre>
<hr />
<p><strong>技术分析之HQL的查询演示</strong></p>
<pre><code>1. HQL基本的查询格式
    * 支持方法链的编程，即直接调用list()方法
    * 简单的代码如下
        * session.createQuery("from Customer").list();

2. 使用别名的方式
    * 可以使用别名的方式
        * session.createQuery("from Customer c").list();
        * session.createQuery("select c from Customer c").list();

3. 排序查询
    * 排序查询和SQL语句中的排序的语法是一样的
        * 升序
            * session.createQuery("from Customer order by cust_id").list();

        * 降序
            * session.createQuery("from Customer order by cust_id desc").list();

4. 分页查询
    * Hibernate框架提供了分页的方法，咱们可以调用方法来完成分页
    * 两个方法如下
        * setFirstResult(a)     -- 从哪条记录开始，如果查询是从第一条开启，值是0
        * setMaxResults(b)      -- 每页查询的记录条数

    * 演示代码如下
        * List&lt;LinkMan&gt; list = session.createQuery("from LinkMan").setFirstResult(0).setMaxResults().list();

5. 带条件的查询
    * setParameter("?号的位置，默认从0开始","参数的值"); 不用考虑参数的具体类型
    * 按位置绑定参数的条件查询（指定下标值，默认从0开始）
    * 按名称绑定参数的条件查询（HQL语句中的 ? 号换成 :名称 的方式）
    * 例如代码如下
        Query query = session.createQuery("from Linkman where lkm_name like ? order by lkm_id desc");
        query.setFirstResult(0).setMaxResults(3);
        query.setParameter(0, "%熊%");
        List&lt;Linkman&gt; list = query.list();
        for (Linkman linkman : list) {
            System.out.println(linkman);
        }
</code></pre>
<hr />
<p><strong>HQL的投影查询</strong></p>
<pre><code>1. 投影查询就是想查询某一字段的值或者某几个字段的值
2. 投影查询的案例
    * 如果查询多个字段，例如下面这种方式
        List&lt;Object[]&gt; list = session.createQuery("select c.cust_name,c.cust_level from Customer c").list();
        for (Object[] objects : list) {
            System.out.println(Arrays.toString(objects));
        }

    * 如果查询两个字段，也可以把这两个字段封装到对象中
        * 先在持久化类中提供对应字段的构造方法
        * 使用下面这种HQL语句的方式
            List&lt;Customer&gt; list = session.createQuery("select new Customer(c.cust_name,c.cust_level) from Customer c").list();
            for (Customer customer : list) {
                System.out.println(customer);
            }
</code></pre>
<hr />
<p><strong>技术分析之聚合函数查询</strong></p>
<pre><code>1. 获取总的记录数
    Session session = HibernateUtils.getCurrentSession();
    Transaction tr = session.beginTransaction();
    List&lt;Number&gt; list = session.createQuery("select count(c) from Customer c").list();
    Long count = list.get(0).longValue();
    System.out.println(count);
    tr.commit();

2. 获取某一列数据的和
    Session session = HibernateUtils.getCurrentSession();
    Transaction tr = session.beginTransaction();
    List&lt;Number&gt; list = session.createQuery("select sum(c.cust_id) from Customer c").list();
    Long count = list.get(0).longValue();
    System.out.println(count);
    tr.commit();
</code></pre>
<hr />
<p><strong>技术分析之QBC检索方式</strong></p>
<pre><code>0. QBC：Query By Criteria  按条件进行查询

1. 简单查询，使用的是Criteria接口
    List&lt;Customer&gt; list = session.createCriteria(Customer.class).list();
    for (Customer customer : list) {
        System.out.println(customer);
    }

2. 排序查询
    * 需要使用addOrder()的方法来设置参数，参数使用org.hibernate.criterion.Order对象
    * 具体代码如下：
        Session session = HibernateUtils.getCurrentSession();
        Transaction tr = session.beginTransaction();
        Criteria criteria = session.createCriteria(Linkman.class);
        // 设置排序
        criteria.addOrder(Order.desc("lkm_id"));
        List&lt;Linkman&gt; list = criteria.list();
        for (Linkman linkman : list) {
            System.out.println(linkman);
        }
        tr.commit();

3. 分页查询
    * QBC的分页查询也是使用两个方法
        * setFirstResult();
        * setMaxResults();

    * 代码如下;
        Session session = HibernateUtils.getCurrentSession();
        Transaction tr = session.beginTransaction();
        Criteria criteria = session.createCriteria(Linkman.class);
        // 设置排序
        criteria.addOrder(Order.desc("lkm_id"));
        criteria.setFirstResult(0);
        criteria.setMaxResults(3);
        List&lt;Linkman&gt; list = criteria.list();
        for (Linkman linkman : list) {
            System.out.println(linkman);
        }
        tr.commit();

4. 条件查询（Criterion是查询条件的接口，Restrictions类是Hibernate框架提供的工具类，使用该工具类来设置查询条件）
    * 条件查询使用Criteria接口的add方法，用来传入条件。
    * 使用Restrictions的添加条件的方法，来添加条件，例如：
        * Restrictions.eq           -- 相等
        * Restrictions.gt           -- 大于号
        * Restrictions.ge           -- 大于等于
        * Restrictions.lt           -- 小于
        * Restrictions.le           -- 小于等于
        * Restrictions.between      -- 在之间
        * Restrictions.like         -- 模糊查询
        * Restrictions.in           -- 范围
        * Restrictions.and          -- 并且
        * Restrictions.or           -- 或者

    * 测试代码如下
        Session session = HibernateUtils.getCurrentSession();
        Transaction tr = session.beginTransaction();
        Criteria criteria = session.createCriteria(Linkman.class);
        // 设置排序
        criteria.addOrder(Order.desc("lkm_id"));
        // 设置查询条件
        criteria.add(Restrictions.or(Restrictions.eq("lkm_gender", "男"), Restrictions.gt("lkm_id", 3L)));
        List&lt;Linkman&gt; list = criteria.list();
        for (Linkman linkman : list) {
            System.out.println(linkman);
        }
        tr.commit();

5. 聚合函数查询（Projection的聚合函数的接口，而Projections是Hibernate提供的工具类，使用该工具类设置聚合函数查询）
    * 使用QBC的聚合函数查询，需要使用criteria.setProjection()方法
    * 具体的代码如下
        Session session = HibernateUtils.getCurrentSession();
        Transaction tr = session.beginTransaction();
        Criteria criteria = session.createCriteria(Linkman.class);
        criteria.setProjection(Projections.rowCount());
        List&lt;Number&gt; list = criteria.list();
        Long count = list.get(0).longValue();
        System.out.println(count);
        tr.commit();
</code></pre>
<hr />
<p><strong>技术分析之离线条件查询</strong></p>
<pre><code>1. 离线条件查询使用的是DetachedCriteria接口进行查询，离线条件查询对象在创建的时候，不需要使用Session对象，只是在查询的时候使用Session对象即可。
2. 创建离线条件查询对象
    * DetachedCriteria criteria = DetachedCriteria.forClass(Linkman.class);

3. 具体的代码如下
    Session session = HibernateUtils.getCurrentSession();
    Transaction tr = session.beginTransaction();

    DetachedCriteria criteria = DetachedCriteria.forClass(Linkman.class);
    // 设置查询条件
    criteria.add(Restrictions.eq("lkm_gender", "男"));
    // 查询数据
    List&lt;Linkman&gt; list = criteria.getExecutableCriteria(session).list();
    for (Linkman linkman : list) {
        System.out.println(linkman);
    }
    tr.commit();
</code></pre>
<hr />
<p><strong>技术分析之SQL查询方式（了解）</strong></p>
<pre><code>1. 基本语法
    Session session = HibernateUtils.getCurrentSession();
    Transaction tr = session.beginTransaction();

    SQLQuery sqlQuery = session.createSQLQuery("select * from cst_linkman where lkm_gender = ?");
    sqlQuery.setParameter(0,"男");
    sqlQuery.addEntity(Linkman.class);
    List&lt;Linkman&gt; list = sqlQuery.list();
    System.out.println(list);
    tr.commit();
</code></pre>
<hr />
<p><strong>技术分析之HQL多表查询</strong></p>
<pre><code>1. 多表的查询进来使用HQL语句进行查询，HQL语句和SQL语句的查询语法比较类似。
    * 内连接查询
        * 显示内连接
            * select * from customers c inner join orders o on c.cid = o.cno;
        * 隐式内连接
            * select * from customers c,orders o where c.cid = o.cno;

    * 外连接查询
        * 左外连接
            * select * from customers c left join orders o on c.cid = o.cno;
        * 右外连接
            * select * from customers c right join orders o on c.cid = o.cno;

2. HQL的多表查询
    * 迫切和非迫切：
        * 非迫切返回结果是Object[]
        * 迫切连接返回的结果是对象，把客户的信息封装到客户的对象中，把订单的信息封装到客户的Set集合中。

3. 内连接查询
    * 内连接使用 inner join ，默认返回的是Object数组
        Session session = HibernateUtils.getCurrentSession();
        Transaction tr = session.beginTransaction();
        List&lt;Object[]&gt; list = session.createQuery("from Customer c inner join c.linkmans").list();
        for (Object[] objects : list) {
            System.out.println(Arrays.toString(objects));
        }
        tr.commit();

    * 迫切内连接:inner join fetch ，返回的是实体对象
        Session session = HibernateUtils.getCurrentSession();
        Transaction tr = session.beginTransaction();
        List&lt;Customer&gt; list = session.createQuery("from Customer c inner join fetch c.linkmans").list();
        Set&lt;Customer&gt; set = new HashSet&lt;Customer&gt;(list);
        for (Customer customer : set) {
            System.out.println(customer);
        }
        tr.commit();

4. 左外连接查询
    * 左外连接: 封装成List&lt;Object[]&gt;

    * 迫切左外连接
        Session session = HibernateUtils.getCurrentSession();
        Transaction tr = session.beginTransaction();
        List&lt;Customer&gt; list = session.createQuery("from Customer c left join fetch c.linkmans").list();
        Set&lt;Customer&gt; set = new HashSet&lt;Customer&gt;(list);
        for (Customer customer : set) {
            System.out.println(customer);
        }
        tr.commit();
</code></pre>
<hr />
<p><strong>案例一代码实现</strong></p>
<hr />
<h3>案例二：对查询功能优化</h3>
<hr />
<p><strong>需求分析</strong></p>
<pre><code>1. 对Hibernate框架的查询进行优化
</code></pre>
<hr />
<p><strong>技术分析之延迟加载</strong></p>
<pre><code>1. 延迟加载先获取到代理对象，当真正使用到该对象中的属性的时候，才会发送SQL语句，是Hibernate框架提升性能的方式
2. 类级别的延迟加载
    * Session对象的load方法默认就是延迟加载
    * Customer c = session.load(Customer.class, 1L);没有发送SQL语句，当使用该对象的属性时，才发送SQL语句

    * 使类级别的延迟加载失效
        * 在&lt;class&gt;标签上配置lazy=&rdquo;false&rdquo;
        * Hibernate.initialize(Object proxy);

3. 关联级别的延迟加载（查询某个客户，当查看该客户下的所有联系人是是否是延迟加载）
    * 默认是延迟加载
        Session session = HibernateUtils.getCurrentSession();
        Transaction tr = session.beginTransaction();
        Customer c = session.get(Customer.class, 1L);
        System.out.println("=============");
        System.out.println(c.getLinkmans().size());
        tr.commit();
</code></pre>
<hr />
<p><strong>技术分析之Hibernate框架的查询策略</strong></p>
<pre><code>1. 查询策略：使用Hibernate查询一个对象的时候，查询其关联对象.应该如何查询.是Hibernate的一种优化手段!!!    
2. Hibernate框架的检索策略解决的问题
    * 查询的时机
        Customer c1 = (Customer) session.get(Customer.class, 1);
        System.out.println(c1.getLinkmans().size());

        * lazy属性解决查询的时机的问题，需要配置是否采用延迟加载！！

    * 查询的语句形式
        List&lt;Customer&gt; list = session.createQuery("from Customer").list();
        for(Customer c : list){
            System.out.println(c.getLinkmans());
        }

        * fetch属性就可以解决查询语句的形式的问题！！
</code></pre>
<hr />
<p><strong>技术分析之在set标签上配置策略</strong></p>
<pre><code>1. 在&lt;set&gt;标签上使用fetch和lazy属性
    * fetch的取值              -- 控制SQL语句生成的格式
        * select                -- 默认值.发送查询语句
        * join                  -- 连接查询.发送的是一条迫切左外连接!!!配置了join.lazy就失效了
        * subselect             -- 子查询.发送一条子查询查询其关联对象.(需要使用list()方法进行测试)

    * lazy的取值               -- 查找关联对象的时候是否采用延迟!
        * true                  -- 默认.延迟
        * false                 -- 不延迟
        * extra                 -- 及其懒惰

2. set标签上的默认值是fetch="select"和lazy="true"

3. 总结：Hibernate框架都采用了默认值，开发中基本上使用的都是默认值。特殊的情况。
</code></pre>
<hr />
<p><strong>技术分析之在man-to-one标签上配置策略</strong></p>
<pre><code>1. 在&lt;many-to-one&gt;标签上使用fetch和lazy属性
    * fetch的取值      -- 控制SQL的格式.
        * select        -- 默认。发送基本select语句查询
        * join          -- 发送迫切左外连接查询

    * lazy的取值       -- 控制加载关联对象是否采用延迟.
        * false         -- 不采用延迟加载.
        * proxy         -- 默认值.代理.现在是否采用延迟.
            * 由另一端的&lt;class&gt;上的lazy确定.如果这端的class上的lazy=&rdquo;true&rdquo;.proxy的值就是true(延迟加载).
            * 如果class上lazy=&rdquo;false&rdquo;.proxy的值就是false(不采用延迟.)

2. 在&lt;many-to-one&gt;标签上的默认值是fetch="select"和proxy
</code></pre>
<hr />
<p><strong>代码实现</strong></p>
<p><strong>　　TestHQLDemo</strong></p>
<div class="cnblogs_code">
<pre><span style="color: #008080;">  1</span> <span style="color: #0000ff;">package</span><span style="color: #000000;"> com.xujingyang.test ;
</span><span style="color: #008080;">  2</span> 
<span style="color: #008080;">  3</span> <span style="color: #0000ff;">import</span><span style="color: #000000;"> java.util.List ;
</span><span style="color: #008080;">  4</span> <span style="color: #0000ff;">import</span><span style="color: #000000;"> org.hibernate.Query ;
</span><span style="color: #008080;">  5</span> <span style="color: #0000ff;">import</span><span style="color: #000000;"> org.hibernate.Session ;
</span><span style="color: #008080;">  6</span> <span style="color: #0000ff;">import</span><span style="color: #000000;"> org.hibernate.Transaction ;
</span><span style="color: #008080;">  7</span> <span style="color: #0000ff;">import</span><span style="color: #000000;"> org.junit.Test ;
</span><span style="color: #008080;">  8</span> <span style="color: #0000ff;">import</span><span style="color: #000000;"> com.xujingyang.utils.HibernateUtil ;
</span><span style="color: #008080;">  9</span> 
<span style="color: #008080;"> 10</span> <span style="color: #008000;">/**</span>
<span style="color: #008080;"> 11</span> <span style="color: #008000;"> * </span><span style="color: #808080;">@author</span><span style="color: #008000;"> oldmonk
</span><span style="color: #008080;"> 12</span> <span style="color: #008000;"> * @date   2017年4月19日
</span><span style="color: #008080;"> 13</span>  <span style="color: #008000;">*/</span>
<span style="color: #008080;"> 14</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> TestHQLDemo {
</span><span style="color: #008080;"> 15</span>     
<span style="color: #008080;"> 16</span>     <span style="color: #008000;">/**</span>
<span style="color: #008080;"> 17</span> <span style="color: #008000;">     * 排序查询
</span><span style="color: #008080;"> 18</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;"> 19</span> <span style="color: #000000;">    @Test
</span><span style="color: #008080;"> 20</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> demo1() {
</span><span style="color: #008080;"> 21</span>         Session session =<span style="color: #000000;"> HibernateUtil.getSession() ;
</span><span style="color: #008080;"> 22</span>         Transaction transaction =<span style="color: #000000;"> session.beginTransaction() ;
</span><span style="color: #008080;"> 23</span>         Query query = session.createQuery("from Customer order by cust_id desc"<span style="color: #000000;">) ;
</span><span style="color: #008080;"> 24</span>         List&lt;Customer&gt; list =<span style="color: #000000;"> query.list() ;
</span><span style="color: #008080;"> 25</span>         <span style="color: #0000ff;">for</span><span style="color: #000000;"> (Customer customer : list) {
</span><span style="color: #008080;"> 26</span> <span style="color: #000000;">            System.out.println(customer) ;
</span><span style="color: #008080;"> 27</span> <span style="color: #000000;">        }
</span><span style="color: #008080;"> 28</span>         
<span style="color: #008080;"> 29</span> <span style="color: #000000;">        transaction.commit() ;
</span><span style="color: #008080;"> 30</span> <span style="color: #000000;">    }
</span><span style="color: #008080;"> 31</span>     
<span style="color: #008080;"> 32</span>     <span style="color: #008000;">/**</span>
<span style="color: #008080;"> 33</span> <span style="color: #008000;">     * 检索查询
</span><span style="color: #008080;"> 34</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;"> 35</span> <span style="color: #000000;">    @Test
</span><span style="color: #008080;"> 36</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> demo2() {
</span><span style="color: #008080;"> 37</span>         Session session =<span style="color: #000000;"> HibernateUtil.getSession() ;
</span><span style="color: #008080;"> 38</span>         Transaction transaction =<span style="color: #000000;"> session.beginTransaction() ;
</span><span style="color: #008080;"> 39</span>         <span style="color: #008000;">//</span><span style="color: #008000;"> Query query = session.createQuery("from Customer where cust_id=?") ;
</span><span style="color: #008080;"> 40</span>         <span style="color: #008000;">//</span><span style="color: #008000;"> query.setLong(0, 2L);</span>
<span style="color: #008080;"> 41</span>         Query query = session.createQuery("from Customer where cust_id=2"<span style="color: #000000;">) ;
</span><span style="color: #008080;"> 42</span>         List&lt;Customer&gt; list =<span style="color: #000000;"> query.list() ;
</span><span style="color: #008080;"> 43</span>         <span style="color: #0000ff;">for</span><span style="color: #000000;"> (Customer customer : list) {
</span><span style="color: #008080;"> 44</span> <span style="color: #000000;">            System.out.println(customer) ;
</span><span style="color: #008080;"> 45</span> <span style="color: #000000;">        }
</span><span style="color: #008080;"> 46</span>         
<span style="color: #008080;"> 47</span> <span style="color: #000000;">        transaction.commit() ;
</span><span style="color: #008080;"> 48</span> <span style="color: #000000;">    }
</span><span style="color: #008080;"> 49</span>     
<span style="color: #008080;"> 50</span>     <span style="color: #008000;">/**</span>
<span style="color: #008080;"> 51</span> <span style="color: #008000;">     * 分页查询
</span><span style="color: #008080;"> 52</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;"> 53</span> <span style="color: #000000;">    @Test
</span><span style="color: #008080;"> 54</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> demo3() {
</span><span style="color: #008080;"> 55</span>         Session session =<span style="color: #000000;"> HibernateUtil.getSession() ;
</span><span style="color: #008080;"> 56</span>         Transaction transaction =<span style="color: #000000;"> session.beginTransaction() ;
</span><span style="color: #008080;"> 57</span>         Query query = session.createQuery("from Customer"<span style="color: #000000;">) ;
</span><span style="color: #008080;"> 58</span>         query.setFirstResult(0) ;<span style="color: #008000;">//</span><span style="color: #008000;"> 从第几条记录开始</span>
<span style="color: #008080;"> 59</span>         query.setMaxResults(2) ;<span style="color: #008000;">//</span><span style="color: #008000;"> 每页显示几条数据</span>
<span style="color: #008080;"> 60</span>         List&lt;Customer&gt; list =<span style="color: #000000;"> query.list() ;
</span><span style="color: #008080;"> 61</span>         <span style="color: #0000ff;">for</span><span style="color: #000000;"> (Customer customer : list) {
</span><span style="color: #008080;"> 62</span> <span style="color: #000000;">            System.out.println(customer) ;
</span><span style="color: #008080;"> 63</span> <span style="color: #000000;">        }
</span><span style="color: #008080;"> 64</span>         
<span style="color: #008080;"> 65</span> <span style="color: #000000;">        transaction.commit() ;
</span><span style="color: #008080;"> 66</span> <span style="color: #000000;">    }
</span><span style="color: #008080;"> 67</span>     
<span style="color: #008080;"> 68</span>     <span style="color: #008000;">/**</span>
<span style="color: #008080;"> 69</span> <span style="color: #008000;">     * 统计查询
</span><span style="color: #008080;"> 70</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;"> 71</span> <span style="color: #000000;">    @Test
</span><span style="color: #008080;"> 72</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> demo4() {
</span><span style="color: #008080;"> 73</span>         Session session =<span style="color: #000000;"> HibernateUtil.getSession() ;
</span><span style="color: #008080;"> 74</span>         Transaction transaction =<span style="color: #000000;"> session.beginTransaction() ;
</span><span style="color: #008080;"> 75</span>         Query query = session.createQuery("select count(1) from Customer"<span style="color: #000000;">) ;
</span><span style="color: #008080;"> 76</span>         List list =<span style="color: #000000;"> query.list() ;
</span><span style="color: #008080;"> 77</span>         System.out.println(list.get(0<span style="color: #000000;">)) ;
</span><span style="color: #008080;"> 78</span>         
<span style="color: #008080;"> 79</span> <span style="color: #000000;">        transaction.commit() ;
</span><span style="color: #008080;"> 80</span> <span style="color: #000000;">    }
</span><span style="color: #008080;"> 81</span>     
<span style="color: #008080;"> 82</span>     <span style="color: #008000;">/**</span>
<span style="color: #008080;"> 83</span> <span style="color: #008000;">     * 投影查询
</span><span style="color: #008080;"> 84</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;"> 85</span> <span style="color: #000000;">    @Test
</span><span style="color: #008080;"> 86</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> demo5() {
</span><span style="color: #008080;"> 87</span>         Session session =<span style="color: #000000;"> HibernateUtil.getSession() ;
</span><span style="color: #008080;"> 88</span>         Transaction transaction =<span style="color: #000000;"> session.beginTransaction() ;
</span><span style="color: #008080;"> 89</span>         Query query = session.createQuery("select cust_id from Customer"<span style="color: #000000;">) ;
</span><span style="color: #008080;"> 90</span>         List list =<span style="color: #000000;"> query.list() ;
</span><span style="color: #008080;"> 91</span>         
<span style="color: #008080;"> 92</span>         <span style="color: #0000ff;">for</span><span style="color: #000000;"> (Object object : list) {
</span><span style="color: #008080;"> 93</span> <span style="color: #000000;">            System.err.println(object) ;
</span><span style="color: #008080;"> 94</span> <span style="color: #000000;">        }
</span><span style="color: #008080;"> 95</span> <span style="color: #000000;">        transaction.commit() ;
</span><span style="color: #008080;"> 96</span> <span style="color: #000000;">    }
</span><span style="color: #008080;"> 97</span>     
<span style="color: #008080;"> 98</span>     <span style="color: #008000;">/**</span>
<span style="color: #008080;"> 99</span> <span style="color: #008000;">     * 连接查询
</span><span style="color: #008080;">100</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;">101</span> <span style="color: #000000;">    @Test
</span><span style="color: #008080;">102</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> demo6() {
</span><span style="color: #008080;">103</span>         Session session =<span style="color: #000000;"> HibernateUtil.getSession() ;
</span><span style="color: #008080;">104</span>         Transaction transaction =<span style="color: #000000;"> session.beginTransaction() ;
</span><span style="color: #008080;">105</span>         
<span style="color: #008080;">106</span>         Query query = session.createQuery("from Customer c inner join fetch c.linkmans "<span style="color: #000000;">) ;
</span><span style="color: #008080;">107</span>         List&lt;Object []&gt; list =<span style="color: #000000;"> query.list() ;
</span><span style="color: #008080;">108</span>         <span style="color: #0000ff;">for</span><span style="color: #000000;"> (Object [] objects : list) {
</span><span style="color: #008080;">109</span>             <span style="color: #0000ff;">for</span><span style="color: #000000;"> (Object object : objects) {
</span><span style="color: #008080;">110</span> <span style="color: #000000;">                System.out.println(object) ;
</span><span style="color: #008080;">111</span> <span style="color: #000000;">            }
</span><span style="color: #008080;">112</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">113</span> <span style="color: #000000;">        transaction.commit() ;
</span><span style="color: #008080;">114</span> <span style="color: #000000;">    }
</span><span style="color: #008080;">115</span>     
<span style="color: #008080;">116</span>     <span style="color: #008000;">/**</span>
<span style="color: #008080;">117</span> <span style="color: #008000;">     * 迫切内连接
</span><span style="color: #008080;">118</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;">119</span> <span style="color: #000000;">    @Test
</span><span style="color: #008080;">120</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> demo7() {
</span><span style="color: #008080;">121</span>         Session session =<span style="color: #000000;"> HibernateUtil.getSession() ;
</span><span style="color: #008080;">122</span>         Transaction transaction =<span style="color: #000000;"> session.beginTransaction() ;
</span><span style="color: #008080;">123</span>         
<span style="color: #008080;">124</span>         Query query = session.createQuery("from Customer c inner join fetch c.linkmans "<span style="color: #000000;">) ;
</span><span style="color: #008080;">125</span>         List&lt;Customer&gt; list =<span style="color: #000000;"> query.list() ;
</span><span style="color: #008080;">126</span>         <span style="color: #0000ff;">for</span><span style="color: #000000;"> (Customer customer : list) {
</span><span style="color: #008080;">127</span> <span style="color: #000000;">            System.out.println(customer) ;
</span><span style="color: #008080;">128</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">129</span> <span style="color: #000000;">        transaction.commit() ;
</span><span style="color: #008080;">130</span> <span style="color: #000000;">    }
</span><span style="color: #008080;">131</span>     <span style="color: #008000;">/**</span>
<span style="color: #008080;">132</span> <span style="color: #008000;">     * 外连接
</span><span style="color: #008080;">133</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;">134</span> <span style="color: #000000;">    @Test
</span><span style="color: #008080;">135</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> demo8() {
</span><span style="color: #008080;">136</span>         Session session =<span style="color: #000000;"> HibernateUtil.getSession() ;
</span><span style="color: #008080;">137</span>         Transaction transaction =<span style="color: #000000;"> session.beginTransaction() ;
</span><span style="color: #008080;">138</span>         
<span style="color: #008080;">139</span>         Query query = session.createQuery("from Customer c left join fetch c.linkmans "<span style="color: #000000;">) ;
</span><span style="color: #008080;">140</span>         List&lt;Customer&gt; list =<span style="color: #000000;"> query.list() ;
</span><span style="color: #008080;">141</span>         <span style="color: #0000ff;">for</span><span style="color: #000000;"> (Customer customer : list) {
</span><span style="color: #008080;">142</span> <span style="color: #000000;">            System.out.println(customer) ;
</span><span style="color: #008080;">143</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">144</span> <span style="color: #000000;">        transaction.commit() ;
</span><span style="color: #008080;">145</span> <span style="color: #000000;">    }
</span><span style="color: #008080;">146</span>     
<span style="color: #008080;">147</span> }</pre>
</div>
<p>&nbsp;</p>
<p>　　<strong>TestQBCDemo</strong></p>
<div class="cnblogs_code">
<pre><span style="color: #008080;">  1</span> <span style="color: #0000ff;">package</span><span style="color: #000000;"> com.xujingyang.test ;
</span><span style="color: #008080;">  2</span> 
<span style="color: #008080;">  3</span> <span style="color: #0000ff;">import</span><span style="color: #000000;"> java.util.List ;
</span><span style="color: #008080;">  4</span> <span style="color: #0000ff;">import</span><span style="color: #000000;"> org.hibernate.Criteria ;
</span><span style="color: #008080;">  5</span> <span style="color: #0000ff;">import</span><span style="color: #000000;"> org.hibernate.Session ;
</span><span style="color: #008080;">  6</span> <span style="color: #0000ff;">import</span><span style="color: #000000;"> org.hibernate.Transaction ;
</span><span style="color: #008080;">  7</span> <span style="color: #0000ff;">import</span><span style="color: #000000;"> org.hibernate.criterion.DetachedCriteria ;
</span><span style="color: #008080;">  8</span> <span style="color: #0000ff;">import</span><span style="color: #000000;"> org.hibernate.criterion.Order ;
</span><span style="color: #008080;">  9</span> <span style="color: #0000ff;">import</span><span style="color: #000000;"> org.hibernate.criterion.Projection ;
</span><span style="color: #008080;"> 10</span> <span style="color: #0000ff;">import</span><span style="color: #000000;"> org.hibernate.criterion.Projections ;
</span><span style="color: #008080;"> 11</span> <span style="color: #0000ff;">import</span><span style="color: #000000;"> org.hibernate.criterion.Restrictions ;
</span><span style="color: #008080;"> 12</span> <span style="color: #0000ff;">import</span><span style="color: #000000;"> org.junit.Test ;
</span><span style="color: #008080;"> 13</span> <span style="color: #0000ff;">import</span><span style="color: #000000;"> com.xujingyang.utils.HibernateUtil ;
</span><span style="color: #008080;"> 14</span> 
<span style="color: #008080;"> 15</span> <span style="color: #008000;">/**</span>
<span style="color: #008080;"> 16</span> <span style="color: #008000;"> * </span><span style="color: #808080;">@author</span><span style="color: #008000;"> oldmonk
</span><span style="color: #008080;"> 17</span> <span style="color: #008000;"> * @date   2017年4月19日
</span><span style="color: #008080;"> 18</span>  <span style="color: #008000;">*/</span>
<span style="color: #008080;"> 19</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> TestQBCDemo {
</span><span style="color: #008080;"> 20</span>     
<span style="color: #008080;"> 21</span>     <span style="color: #008000;">/**</span>
<span style="color: #008080;"> 22</span> <span style="color: #008000;">     * 基本查询
</span><span style="color: #008080;"> 23</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;"> 24</span> <span style="color: #000000;">    @Test
</span><span style="color: #008080;"> 25</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> demo1() {
</span><span style="color: #008080;"> 26</span>         Session session =<span style="color: #000000;"> HibernateUtil.getSession() ;
</span><span style="color: #008080;"> 27</span>         Transaction transaction =<span style="color: #000000;"> session.beginTransaction() ;
</span><span style="color: #008080;"> 28</span>         
<span style="color: #008080;"> 29</span>         Criteria criteria = session.createCriteria(Customer.<span style="color: #0000ff;">class</span><span style="color: #000000;">) ;
</span><span style="color: #008080;"> 30</span>         List&lt;Customer&gt; list =<span style="color: #000000;"> criteria.list() ;
</span><span style="color: #008080;"> 31</span>         <span style="color: #0000ff;">for</span><span style="color: #000000;"> (Customer customer : list) {
</span><span style="color: #008080;"> 32</span> <span style="color: #000000;">            System.out.println(customer) ;
</span><span style="color: #008080;"> 33</span> <span style="color: #000000;">        }
</span><span style="color: #008080;"> 34</span> <span style="color: #000000;">        transaction.commit() ;
</span><span style="color: #008080;"> 35</span> <span style="color: #000000;">    }
</span><span style="color: #008080;"> 36</span>     
<span style="color: #008080;"> 37</span>     <span style="color: #008000;">/**</span>
<span style="color: #008080;"> 38</span> <span style="color: #008000;">     * 条件查询
</span><span style="color: #008080;"> 39</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;"> 40</span> <span style="color: #000000;">    @Test
</span><span style="color: #008080;"> 41</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> demo2() {
</span><span style="color: #008080;"> 42</span>         Session session =<span style="color: #000000;"> HibernateUtil.getSession() ;
</span><span style="color: #008080;"> 43</span>         Transaction transaction =<span style="color: #000000;"> session.beginTransaction() ;
</span><span style="color: #008080;"> 44</span>         
<span style="color: #008080;"> 45</span>         Criteria criteria = session.createCriteria(Customer.<span style="color: #0000ff;">class</span><span style="color: #000000;">) ;
</span><span style="color: #008080;"> 46</span>         <span style="color: #008000;">//</span><span style="color: #008000;"> criteria.add(Restrictions.gt("cust_id", 3L));</span>
<span style="color: #008080;"> 47</span>         criteria.add(Restrictions.between("cust_id", 3L, 4L<span style="color: #000000;">)) ;
</span><span style="color: #008080;"> 48</span>         List&lt;Customer&gt; list =<span style="color: #000000;"> criteria.list() ;
</span><span style="color: #008080;"> 49</span>         <span style="color: #0000ff;">for</span><span style="color: #000000;"> (Customer customer : list) {
</span><span style="color: #008080;"> 50</span> <span style="color: #000000;">            System.out.println(customer) ;
</span><span style="color: #008080;"> 51</span> <span style="color: #000000;">        }
</span><span style="color: #008080;"> 52</span> <span style="color: #000000;">        transaction.commit() ;
</span><span style="color: #008080;"> 53</span> <span style="color: #000000;">    }
</span><span style="color: #008080;"> 54</span>     
<span style="color: #008080;"> 55</span>     <span style="color: #008000;">/**</span>
<span style="color: #008080;"> 56</span> <span style="color: #008000;">     * 分页查询
</span><span style="color: #008080;"> 57</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;"> 58</span> <span style="color: #000000;">    @Test
</span><span style="color: #008080;"> 59</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> demo3() {
</span><span style="color: #008080;"> 60</span>         Session session =<span style="color: #000000;"> HibernateUtil.getSession() ;
</span><span style="color: #008080;"> 61</span>         Transaction transaction =<span style="color: #000000;"> session.beginTransaction() ;
</span><span style="color: #008080;"> 62</span>         
<span style="color: #008080;"> 63</span>         Criteria criteria = session.createCriteria(Customer.<span style="color: #0000ff;">class</span><span style="color: #000000;">) ;
</span><span style="color: #008080;"> 64</span>         criteria.setFirstResult(0<span style="color: #000000;">) ;
</span><span style="color: #008080;"> 65</span>         criteria.setMaxResults(2<span style="color: #000000;">) ;
</span><span style="color: #008080;"> 66</span>         List&lt;Customer&gt; list =<span style="color: #000000;"> criteria.list() ;
</span><span style="color: #008080;"> 67</span>         <span style="color: #0000ff;">for</span><span style="color: #000000;"> (Customer customer : list) {
</span><span style="color: #008080;"> 68</span> <span style="color: #000000;">            System.out.println(customer) ;
</span><span style="color: #008080;"> 69</span> <span style="color: #000000;">        }
</span><span style="color: #008080;"> 70</span> <span style="color: #000000;">        transaction.commit() ;
</span><span style="color: #008080;"> 71</span> <span style="color: #000000;">    }
</span><span style="color: #008080;"> 72</span>     
<span style="color: #008080;"> 73</span>     <span style="color: #008000;">/**</span>
<span style="color: #008080;"> 74</span> <span style="color: #008000;">     * 排序查询
</span><span style="color: #008080;"> 75</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;"> 76</span> <span style="color: #000000;">    @Test
</span><span style="color: #008080;"> 77</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> demo4() {
</span><span style="color: #008080;"> 78</span>         Session session =<span style="color: #000000;"> HibernateUtil.getSession() ;
</span><span style="color: #008080;"> 79</span>         Transaction transaction =<span style="color: #000000;"> session.beginTransaction() ;
</span><span style="color: #008080;"> 80</span>         
<span style="color: #008080;"> 81</span>         Criteria criteria = session.createCriteria(Customer.<span style="color: #0000ff;">class</span><span style="color: #000000;">) ;
</span><span style="color: #008080;"> 82</span>         criteria.addOrder(Order.desc("cust_id"<span style="color: #000000;">)) ;
</span><span style="color: #008080;"> 83</span>         List&lt;Customer&gt; list =<span style="color: #000000;"> criteria.list() ;
</span><span style="color: #008080;"> 84</span>         <span style="color: #0000ff;">for</span><span style="color: #000000;"> (Customer customer : list) {
</span><span style="color: #008080;"> 85</span> <span style="color: #000000;">            System.out.println(customer) ;
</span><span style="color: #008080;"> 86</span> <span style="color: #000000;">        }
</span><span style="color: #008080;"> 87</span> <span style="color: #000000;">        transaction.commit() ;
</span><span style="color: #008080;"> 88</span> <span style="color: #000000;">    }
</span><span style="color: #008080;"> 89</span>     
<span style="color: #008080;"> 90</span>     <span style="color: #008000;">/**</span>
<span style="color: #008080;"> 91</span> <span style="color: #008000;">     * 统计查询
</span><span style="color: #008080;"> 92</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;"> 93</span> <span style="color: #000000;">    @Test
</span><span style="color: #008080;"> 94</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> demo5() {
</span><span style="color: #008080;"> 95</span>         Session session =<span style="color: #000000;"> HibernateUtil.getSession() ;
</span><span style="color: #008080;"> 96</span>         Transaction transaction =<span style="color: #000000;"> session.beginTransaction() ;
</span><span style="color: #008080;"> 97</span>         
<span style="color: #008080;"> 98</span>         Criteria criteria = session.createCriteria(Customer.<span style="color: #0000ff;">class</span><span style="color: #000000;">) ;
</span><span style="color: #008080;"> 99</span>         <span style="color: #008000;">//</span><span style="color: #008000;"> criteria.setProjection(Projections.id());</span>
<span style="color: #008080;">100</span>         criteria.setProjection(Projections.sum("cust_id"<span style="color: #000000;">)) ;
</span><span style="color: #008080;">101</span>         List list =<span style="color: #000000;"> criteria.list() ;
</span><span style="color: #008080;">102</span>         <span style="color: #0000ff;">for</span><span style="color: #000000;"> (Object obj : list) {
</span><span style="color: #008080;">103</span> <span style="color: #000000;">            System.out.println(obj) ;
</span><span style="color: #008080;">104</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">105</span> <span style="color: #000000;">        transaction.commit() ;
</span><span style="color: #008080;">106</span> <span style="color: #000000;">    }
</span><span style="color: #008080;">107</span>     
<span style="color: #008080;">108</span>     <span style="color: #008000;">/**</span>
<span style="color: #008080;">109</span> <span style="color: #008000;">     * 离线条件查询:DetachedCriteria(SSH整合经常使用.).
</span><span style="color: #008080;">110</span> <span style="color: #008000;">     * * 可以脱离session设置参数.
</span><span style="color: #008080;">111</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;">112</span> <span style="color: #000000;">    @Test
</span><span style="color: #008080;">113</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> demo6() {
</span><span style="color: #008080;">114</span>         DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Customer.<span style="color: #0000ff;">class</span><span style="color: #000000;">) ;
</span><span style="color: #008080;">115</span>         detachedCriteria.add(Restrictions.gt("cust_id", 3L<span style="color: #000000;">)) ;
</span><span style="color: #008080;">116</span>         Session session =<span style="color: #000000;"> HibernateUtil.getSession() ;
</span><span style="color: #008080;">117</span>         Transaction transaction =<span style="color: #000000;"> session.beginTransaction() ;
</span><span style="color: #008080;">118</span>         
<span style="color: #008080;">119</span>         List list =<span style="color: #000000;"> detachedCriteria.getExecutableCriteria(session).list() ;
</span><span style="color: #008080;">120</span>         <span style="color: #0000ff;">for</span><span style="color: #000000;"> (Object obj : list) {
</span><span style="color: #008080;">121</span> <span style="color: #000000;">            System.out.println(obj) ;
</span><span style="color: #008080;">122</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">123</span> <span style="color: #000000;">        transaction.commit() ;
</span><span style="color: #008080;">124</span> <span style="color: #000000;">    }
</span><span style="color: #008080;">125</span>     
<span style="color: #008080;">126</span> }</pre>
</div>
<p>&nbsp;</p></div><div id="MySignature"></div>
<div class="clear"></div>
<div id="blog_post_info_block">
<div id="BlogPostCategory"></div>
<div id="EntryTag"></div>
<div id="blog_post_info">
</div>
<div class="clear"></div>
<div id="post_next_prev"></div>
</div>


		</div>
		<div class = "postDesc">posted @ <span id="post-date">2017-04-19 16:39</span> <a href='http://www.cnblogs.com/xujingyang/'>oldmonk</a> 阅读(<span id="post_view_count">...</span>) 评论(<span id="post_comment_count">...</span>)  <a href ="https://i.cnblogs.com/EditPosts.aspx?postid=6734203" rel="nofollow">编辑</a> <a href="#" onclick="AddToWz(6734203);return false;">收藏</a></div>
	</div>
	<script type="text/javascript">var allowComments=true,cb_blogId=234959,cb_entryId=6734203,cb_blogApp=currentBlogApp,cb_blogUserGuid='e2234c32-1127-e511-b908-9dcfd8948a71',cb_entryCreatedDate='2017/4/19 16:39:00';loadViewCount(cb_entryId);var cb_postType=1;</script>
	
</div><!--end: topics 文章、评论容器-->
</div><a name="!comments"></a><div id="blog-comments-placeholder"></div><script type="text/javascript">var commentManager = new blogCommentManager();commentManager.renderComments(0);</script>
<div id='comment_form' class='commentform'>
<a name='commentform'></a>
<div id='divCommentShow'></div>
<div id='comment_nav'><span id='span_refresh_tips'></span><a href='javascript:void(0);' onclick='return RefreshCommentList();' id='lnk_RefreshComments' runat='server' clientidmode='Static'>刷新评论</a><a href='#' onclick='return RefreshPage();'>刷新页面</a><a href='#top'>返回顶部</a></div>
<div id='comment_form_container'></div>
<div class='ad_text_commentbox' id='ad_text_under_commentbox'></div>
<div id='ad_t2'></div>
<div id='opt_under_post'></div>
<div id='cnblogs_c1' class='c_ad_block'></div>
<div id='under_post_news'></div>
<div id='cnblogs_c2' class='c_ad_block'></div>
<div id='under_post_kb'></div>
<div id='HistoryToday' class='c_ad_block'></div>
<script type='text/javascript'>
    fixPostBody();
    setTimeout(function () { incrementViewCount(cb_entryId); }, 50);
    deliverAdT2();
    deliverAdC1();
    deliverAdC2();    
    loadNewsAndKb();
    loadBlogSignature();
    LoadPostInfoBlock(cb_blogId, cb_entryId, cb_blogApp, cb_blogUserGuid);
    GetPrevNextPost(cb_entryId, cb_blogId, cb_entryCreatedDate, cb_postType);
    loadOptUnderPost();
    GetHistoryToday(cb_blogId, cb_blogApp, cb_entryCreatedDate);   
</script>
</div>


	</div><!--end: forFlow -->
	</div><!--end: mainContent 主体内容容器-->

	<div id="sideBar">
		<div id="sideBarMain">
			
<!--done-->
<div class="newsItem">
<h3 class="catListTitle">公告</h3>
	<div id="blog-news"></div><script type="text/javascript">loadBlogNews();</script>
</div>

			<div id="calendar"><div id="blog-calendar" style="display:none"></div><script type="text/javascript">loadBlogDefaultCalendar();</script></div>
			
			<DIV id="leftcontentcontainer">
				<div id="blog-sidecolumn"></div><script type="text/javascript">loadBlogSideColumn();</script>
			</DIV>
			
		</div><!--end: sideBarMain -->
	</div><!--end: sideBar 侧边栏容器 -->
	<div class="clear"></div>
	</div><!--end: main -->
	<div class="clear"></div>
	<div id="footer">
		
<!--done-->
Copyright &copy;2017 oldmonk
	</div><!--end: footer -->
</div><!--end: home 自定义的最大容器 -->
</body>
</html>
